{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-30T14:14:03.768402Z",
     "start_time": "2019-07-30T14:14:02.809217Z"
    }
   },
   "outputs": [],
   "source": [
    "# Code snippet to check correlation between two sets of relevance assessment (e.g., made by different cohorts - assessments made by medical doctors Vs. crowdsourced assessments)\n",
    "from trectools import  TrecQrel\n",
    "\n",
    "original_qrels_file =  \"./robust03/qrel/robust03_qrels.txt\"\n",
    "\n",
    "# Changed the first 10 assessments from 0 to 1\n",
    "modified_qrels_file = \"./robust03/qrel/mod_robust03_qrels.txt\"\n",
    "\n",
    "original_qrels = TrecQrel(original_qrels_file)\n",
    "modified_qrels = TrecQrel(modified_qrels_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-30T14:14:03.849850Z",
     "start_time": "2019-07-30T14:14:03.770234Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9999223578372"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Overall agreement \n",
    "original_qrels.check_agreement(modified_qrels) # 0.99"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-30T14:14:03.926948Z",
     "start_time": "2019-07-30T14:14:03.851308Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P0: 1.00, Pe = 0.90\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.999188229143584"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Fleiss' kappa agreement\n",
    "original_qrels.check_kappa(modified_qrels) # P0: 1.00, Pe = 0.90"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-07-30T14:14:04.067989Z",
     "start_time": "2019-07-30T14:14:03.928210Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[122712,     10,      0],\n",
       "       [     0,   5667,      0],\n",
       "       [     0,      0,    407]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3x3 confusion matrix (labels 0, 1 or 2) \n",
    "original_qrels.check_confusion_matrix(modified_qrels)\n",
    "# [[122712     10      0]\n",
    "# [     0   5667      0]\n",
    "# [     0      0    407]]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
